package com.sanchunhui.psc.presenter

import com.sanchunhui.psc.data.protocol.ResponseInfo
import com.sanchunhui.psc.ext.excute
import com.sanchunhui.psc.presenter.view.UserInfoView
import com.sanchunhui.psc.rx.BaseSubscriber
import com.sanchunhui.psc.service.UploadService
import com.sanchunhui.psc.service.UserService
import okhttp3.MultipartBody
import okhttp3.RequestBody
import javax.inject.Inject

/*
    编辑用户资料Presenter
 */
class UserInfoPresenter @Inject constructor() : BasePresenter<UserInfoView>() {

    @Inject
    lateinit var userService: UserService

    @Inject
    lateinit var uploadService: UploadService

    /*
        获取七牛云上传凭证
     */
//    fun getUploadToken(){
//        if (!checkNetWork())
//            return
//
//        mView.showLoading()
//        uploadService.getUploadToken().excute(object : BaseSubscriber<String>(mView){
//            override fun onNext(t: String) {
//                mView.onGetUploadTokenResult(t)
//            }
//        },lifecycleProvider)
//    }

    fun uploadUserHead(tokenStr:RequestBody, files:MultipartBody.Part){
        if (!checkNetWork())
            return

        mView.showLoading()
        uploadService.uploadUserHead(tokenStr,files).excute(object : BaseSubscriber<ResponseInfo>(mView){
            override fun onNext(t: ResponseInfo) {
                mView.onGetUploadHeadResult(t)
            }

        },lifecycleProvider)
    }

    /*
        编辑用户资料
     */
    fun editUser(userIcon:String,userName:String,userGender:String){
        if (!checkNetWork())
            return

        mView.showLoading()
        userService.editUser(userIcon,userName,userGender).excute(object :BaseSubscriber<ResponseInfo>(mView){
            override fun onNext(t: ResponseInfo) {
                mView.onEditUserResult(t)
            }
        },lifecycleProvider)
    }

}
